package com.example.springboot.controller;

import com.example.springboot.model.Student;
import com.example.springboot.service.StudentService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author NardinVN
 */
@RestController
@RequestMapping("/api/v1/students")
@AllArgsConstructor
public class StudentController {

//    @Autowired Устаревшее
    private StudentService service;

    @GetMapping
    public List<Student> findAllStudents() {
        //TODO
        return service.findAllStudents();
    }

    // @RequestBody для серилизации получаемого объекта Спрингом
    @PostMapping("save_student")
    public String saveStudent(@RequestBody Student student) {
        service.saveStudent(student);
        return "SUCCESS";
    }

    @GetMapping("/{email}")
    public Student findByEmail(@PathVariable String email) {
        return service.findByEmail(email);
    }

    @PutMapping("update_student")
    public Student updateStudent(Student student) {
        return service.updateStudent(student);
    }

    @DeleteMapping("delete_student/{email}")
    public void deleteStudent(@PathVariable String email) {
        service.deleteStudent(email);
    }

}
